import type { MenuOption } from 'naive-ui';

/**
 * 过滤菜单
 *
 * @param menus 菜单数组
 */
export function filterMenus(menus: Recordable[]) {
  return menus.filter(menu => !menu.hidden);
}

/**
 * 转换界面菜单数据
 *
 * @param menus 菜单列表
 */
export function convertUiMenus(menus: Recordable[]): MenuOption[] {
  return menus
    .filter(menu => !menu.hidden)
    .map(menu => {
      return {
        icon: menu.meta.icon,
        redirect: menu.redirect,
        link: menu.meta.link,
        label: menu.meta?.title,
        key: menu.path,
        children: menu.children?.length ? convertUiMenus(menu.children) : undefined,
      };
    });
}
